package com.usian.controller;

import com.usian.feign.ItemFeign;
import com.usian.pojo.TbItemParam;
import com.usian.utils.PageResult;
import com.usian.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/backend/itemParam")
public class ItemParamController {

    @Autowired
    private ItemFeign itemFeign;



    /**
     * 根据ItemCatId查找 Item主页面查看
     * @param itemCatId
     * @return
     */
    @RequestMapping("selectItemParamByItemCatId/{itemCatId}")
    public Result selectItemParamByItemCatId(@PathVariable(value = "itemCatId") Integer itemCatId){
        TbItemParam itemParam = itemFeign.selectItemParamByItemCatId(itemCatId);
        if (itemParam!=null){
            return Result.ok(itemParam);
        }
        return Result.error("查无结果");
    }

    @RequestMapping("selectItemParamAll")
    public Result selectItemParamAll(){
        PageResult pageResult = itemFeign.selectItemParamAll();
        if (pageResult.getResult()!=null && pageResult.getResult().size()>0){
            return Result.ok(pageResult);
        }
        return Result.error("查无结果");
    }

    @RequestMapping("insertItemParam")
    public Result insertItemParam(@RequestParam Long itemCatId,@RequestParam String[] paramData){
        Boolean falg = itemFeign.insertItemParam(itemCatId,paramData);
        if (falg){
            return Result.ok();
        }
        return Result.error("添加失败");
    }

    @RequestMapping("deleteItemParamById")
    public Result deleteItemParamById(@RequestParam Long id){
        Boolean falg = itemFeign.deleteItemParamById(id);
        if (falg){
            return Result.ok();
        }
        return Result.error("删除失败");
    }


}
